package net.xiezihao.product_service.controller;

import jdk.nashorn.internal.ir.annotations.Reference;
import net.xiezihao.product_service.domain.Product;
import net.xiezihao.product_service.service.ProductService;
import net.xiezihao.product_service.service.UserServiceFeignClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/v1/product")
@RefreshScope
public class ProductController {
    private final Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    private ProductService productService;
    @Value("${sb}")
    private String sb;

    /**
     * 获取所有商品列表
     *
     * @return
     */
    @RequestMapping("/list")
    public Object list() {
        logger.info("product list");
        return productService.listProduct();
    }

    /**
     * 根据id获取商品
     *
     * @param id
     * @return
     */
    @RequestMapping("/find")
    public Object findById(@RequestParam("id") int id) {
        logger.info("product find");
        return productService.findById(id);
    }

    @RequestMapping("/diaoyong")
    public Object diaoyong() {
        logger.info("project diaoyong");
        Map diaoyong = productService.diaoyong();
        diaoyong.put("sb", sb);
        return diaoyong;
    }
}
